﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Jackie.Silverliight.SetpBySetp.BlogService;

namespace Jackie.Silverliight.SetpBySetp.WCF
{
    public partial class GetData : Page
    {
        public GetData()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(GetData_Loaded);
        }

        void GetData_Loaded(object sender, RoutedEventArgs e)
        {
            Binding binding = new BasicHttpBinding();
            EndpointAddress endpoint = new EndpointAddress("http://localhost:1100/Wcf/Blog.svc?wsdl");

            BlogService.BlogClient client = new BlogClient(binding, endpoint);
            client.GetPostsCompleted += new EventHandler<GetPostsCompletedEventArgs>(client_GetPostsCompleted);
            client.GetPostsAsync();
        }

        void client_GetPostsCompleted(object sender, GetPostsCompletedEventArgs e)
        {
            if(e.Error==null)
                lbPost.ItemsSource = e.Result;
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

    }
}
